package dubbo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

/**
 * Hello world!
 *
 */
@SpringBootApplication
@ImportResource(value = { "classpath:dubbo.xml","classpath:spring-disconf.xml" })
public class App4 {
/**
 * 使用整合Spring boot框架启动服务，并调用其他两个服务server1和server2
 * @param args
 */
	public static void main(String[] args) {
		//QuasarIncreasingTest.compare();
		//QuasarIncreasingTest.recycle();
		SpringApplication.run(App4.class, args);
		System.out.println("===============================================================================");
		System.out.println("============= APP4 Started ON SpringBoot Success FOR dubbo.server4=============");
		System.out.println("===============================================================================");
	}
	/**
	 * 想同时使用webservice和Httprest对外提供服务，就得配置这个东东
	 * @return
	 */
	@Bean
	public ServletRegistrationBean restServlet() {
		//注解扫描上下文
		AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
		//项目包名
		applicationContext.scan("dubbo.server4.impl");
		DispatcherServlet rest_dispatcherServlet = new DispatcherServlet(applicationContext);
		ServletRegistrationBean registrationBean = new ServletRegistrationBean(rest_dispatcherServlet);
		registrationBean.setLoadOnStartup(1);
		registrationBean.addUrlMappings("/*");
		return registrationBean;
	}
}
